using UnityEngine;
/// <summary>
/// 梯子状态
/// </summary>

public class PlayerLadderState : PlayerState
{
    public PlayerLadderState(PlayerFSM manager, string animationName) : base(manager, animationName) { }

    public override void OnEnter()
    {
        base.OnEnter();
        parameter.rb.gravityScale = 0;
        SetVelocity(0, 0);//速度清0
        //固定玩家x轴位置在梯子中间
        manager.transform.position = new Vector2(parameter.check.ladderTransform.position.x, manager.transform.position.y);
    }

    public override void OnUpdate()
    {
        base.OnUpdate();
        
        if ((parameter.check.isTouchGround && parameter.inputDirection.y <= 0) || !parameter.check.isTouchLadder)
        {
            manager.TransitionState(StateType.Idle);
        }
        if (parameter.isClickJump)
        {
            manager.TransitionState(StateType.Jump);
        }
    }

    public override void OnFixedUpdate()
    {
        base.OnFixedUpdate();
        //没有上下移动，停止暂停玩家动画播放
        if(parameter.inputDirection.y == 0){
            parameter.animator.speed = 0;
            SetVelocity(0, 0);
        }else{
            parameter.animator.speed = 1;
            SetVelocity(0, parameter.ladderSpeed * parameter.inputDirection.y);
        }
    }

    public override void OnExit()
    {
        base.OnExit();
        parameter.animator.speed = 1;
        parameter.rb.gravityScale = parameter.Gravity;
    }
}
